@ echo off 


REM Pause SQL Server to take Snapshot
REM \<folder> is the folder containing DButil
REM DButil is called to prepare the database for backup.
REM usage: DButil <function> <SQL Server Name> <database name> <user> <password>
REM -pre is the function to prepare the database for snapshot backup

cd \<folder>
DButil -pre VSMSQL MyDatabase dba password


REM Create new snapshot of virtual disks
REM This MUST be done for each volume that has database files

cd\
SNAPMGR SNAPSHOT "SnapD1" /PARENT:"Data1"
SNAPMGR SNAPSHOT "SnapD2" /PARENT:"Data2"

REM Resume SQL Server
REM -post option to DButil ends the SQL backup mode started by -pre

cd \<folder>
DButil -post VSMSQL MyDatabase dba password

REM Map drive letter for the new snapshot

cd\
SNAPMGR SNAPSHOT "SnapD1"/MAP:W
SNAPMGR SNAPSHOT "SnapD2"/MAP:X

REM ** Unmap and Delete old snapshots if exist **

SNAPMGR SNAPSHOT "SnapD1B"/UNMAP
SNAPMGR SNAPSHOT "SnapD2B"/UNMAP 

SNAPMGR SNAPSHOT "SnapD1B"/DELETE
SNAPMGR SNAPSHOT "SnapD2B"/DELETE

Exit
